<template>
  <div :class="className" :style="{height:height,width:width}"/>
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import { debounce } from '@/utils'

const animationDuration = 6000

export default {
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.initChart()
    this.__resizeHandler = debounce(() => {
      if (this.chart) {
        this.chart.resize()
      }
    }, 100)
    window.addEventListener('resize', this.__resizeHandler)
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    window.removeEventListener('resize', this.__resizeHandler)
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
        title: {
            text: '投放计划(单位:万元)',
            
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow' 
          }
        },
        color:[
            "#8cd5ba","#d871d2","#d56760","#acd598",
        ],
        xAxis: [{
          type: 'category',
          data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月',"8月","9月","10月","11月","12月"],
          axisTick: {
            alignWithLabel: true
          }
        }],
        yAxis: [{
          type: 'value',
          axisTick: {
            show: false
          }
        }],
        series: [
            {   name: '计划投放量',
                data: [100, 932, 901, 500, 1290, 1330, 1320,820, 932, 901, 934, 1290, 1330, 1320],
                type: 'line',
                smooth: true,
                itemStyle : {  
                    normal : {  
                        lineStyle:{  
                            color:'#8cd5ba'  
                        }  
                    }  
                },
            },
             {  name: '前两年计划投放量',
                data: [820, 932, 901, 934, 1290, 150, 1320,820, 300, 901, 900, 1290, 1330, 1320],
                type: 'line',
                smooth: true,
                itemStyle : {  
                    normal : {  
                        lineStyle:{  
                            color:'#d871d2'  
                        }  
                    }  
                },
            },
            {   name: '实际投放量',
                data: [300, 932, 901, 934, 1290, 1330, 1320,820, 50, 901, 934, 1290, 1330, 1320],
                type: 'line',
                smooth: true,
                itemStyle : {  
                    normal : {  
                        lineStyle:{  
                            color:'#d56760'  
                        }  
                    }  
                },
            },
            {   name: '前两年计划投放量',
                data: [200, 932, 901, 934, 1290, 750, 1320,820, 932, 901, 934, 1290, 1330, 10],
                type: 'line',
                smooth: true,
                itemStyle : {  
                    normal : {  
                        lineStyle:{  
                            color:'#acd598'  
                        }  
                    }  
                },
            }
        
        ]
      })
    }
  }
}
</script>
